﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AutoMapper;

using Happy.Archetype;
using Happy.Application.Domain;
using Happy.Cms.Domain;
using Happy.Cms.Domain.Articles;
using Happy.Cms.Query.Articles;

namespace Happy.Cms.Application.Articles
{
    [ApplicationService]
    public sealed class ArticleService : AggregateRootService<Article, ArticleView, ICmsUnitOfWork>
    {
        protected override Article CreateAggregate(ArticleView viewModel)
        {
            var aggregate = new Article(Guid.NewGuid());
            aggregate.AssignTags(viewModel.AssignedTags);
            return Mapper.Map(viewModel, aggregate);
        }

        protected override void UpdateAggregate(Article aggregate, ArticleView viewModel)
        {
            aggregate.AssignTags(viewModel.AssignedTags);
            Mapper.Map(viewModel, aggregate);
        }
    }
}
